package com.ctz.commonframe.ui;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.ctz.commonframe.R;
import com.ctz.commonframe.constant.DeviceInfo;


public class BottomMenuDialog extends Dialog {
	public static final int TYPE_IMAGE_CAPTURE = 1;
	public static final int TYPE_IMAGE_OPERATE = 2;
	public static final int TYPE_NORMAL_DELETE = 3;

	private TextView tvMenu1, tvMenu2, tvCancel;
	private View.OnClickListener menu1Listener, menu2Listener;
	private int type;

	public BottomMenuDialog(Context context, int type) {
		super(context, R.style.BottomMenuDialog);
		this.type = type;
	}

	public BottomMenuDialog setOnMenu1ClickListener(View.OnClickListener listener){
		menu1Listener = listener;
		return this;
	}

	public BottomMenuDialog setOnMenu2ClickListener(View.OnClickListener listener){
		menu2Listener = listener;
		return this;
	}

	@Override
	public void show() {
		Window window = getWindow();
		window.setGravity(Gravity.BOTTOM);
		setCanceledOnTouchOutside(true);
		super.show();
		WindowManager.LayoutParams lp = window.getAttributes();
		lp.width = DeviceInfo.screenWidth;
		window.setAttributes(lp);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dialog_bottom_menu);
		tvMenu1 = (TextView) findViewById(R.id.tv_menu1);
		tvMenu2 = (TextView) findViewById(R.id.tv_menu2);
		tvCancel = (TextView) findViewById(R.id.tv_cancel);

		if(type == TYPE_IMAGE_CAPTURE){
			tvMenu1.setText("图片");
			tvMenu2.setText("拍照");
		}else if(type == TYPE_IMAGE_OPERATE){
			tvMenu1.setText("预览");
			tvMenu2.setText("删除");
		}else if(type == TYPE_NORMAL_DELETE) {
			tvMenu1.setVisibility(View.GONE);
			tvMenu2.setText("删除");
		}

		if(menu1Listener != null){
			tvMenu1.setOnClickListener(menu1Listener);
		}

		if(menu2Listener != null){
			tvMenu2.setOnClickListener(menu2Listener);
		}

		tvCancel.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				dismiss();
			}
		});
	}
}